#include<cstdlib>
#include<sq_list.h>
#include<iostream>

using namespace std;

#define InitSize 10  //定义最大长度


void InitList(SqlList &L) {
    L.data = (int *) malloc(InitSize * sizeof(int));
    L.length = 0;
    L.MaxSize = InitSize;
}

void IncreaseSize(SqlList &L, int len) {
    int *p = L.data;
    L.data = (int *) malloc((L.MaxSize + len) * sizeof(int));
    for (int i = 0; i < L.length; i++) {
        L.data[i] = p[i];
    }
    L.MaxSize += len;
    free(p);
}

bool ListInsert(SqlList &L, int i, int e) {
    if (i < 1 || i > L.length + 1) return false;    //i的范围是否有效
    if (L.length >= L.MaxSize) return false;    //当前存储空间已满，不能插入
    for (int j = L.length; j >= i; j--) {
        L.data[j] = L.data[j - 1];
    }
    L.data[i - 1] = e;
    L.length++;
    return true;
}

bool ListDelete(SqlList &L, int i, int &e) {
    if (i < 1 || i > L.length) return false;
    e = L.data[i - 1];
    for (int j = i; j < L.length; j++) {
        L.data[j - 1] = L.data[j];
    }
    L.length--;
    return true;

}

int GetElem(SqlList L, int i) {
    if (i < 1 || i > L.length) return -1;
    return L.data[i - 1];
}

int LocateElem(SqlList L, int e) {
    for (int i = 0; i < L.length; i++) {
        if (L.data[i] == e) return i + 1;
    }
    return -1;
}

bool Delete_s_t(SqlList &L, int s, int t) {
    if (L.length == 0 || s >= t) return false;
    int k = 0;
    for (int i = 0; i < L.length; i++) {
        if (L.data[i] < s || L.data[i] > t) {
            L.data[k++] = L.data[i];
        }
    }
    L.length = k;
    return true;
}

int main() {

    SqlList L;
    InitList(L);
    ListInsert(L, 1, 1);
    ListInsert(L, 2, 6);
    ListInsert(L, 3, 3);
    ListInsert(L, 4, 8);
    ListInsert(L, 5, 2);
    for (int i = 0; i < L.length; i++) {
        cout << L.data[i] << " ";
    }
    cout << endl;
    Delete_s_t(L, 2, 3);
    for (int i = 0; i < L.length; i++) {
        cout << L.data[i] << " ";
    }
    cout << endl;

    return 0;
}